﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace clock
{
    internal class Clock
    {
        public delegate void AlarmHandler(object sender, DateTime args);
        public delegate void TickHanlder(object sender, DateTime args);
        public event AlarmHandler OnAlarm;
        public event TickHanlder OnTick;
        public Clock()
        {
            OnTick += Tick;
            OnAlarm += Alarm;
        }
        public void Tick(object sender, DateTime time)
        {
            Console.WriteLine($"现在是{time}." ); 
        }
        public void Alarm(object sender, DateTime time)
        {
            Console.WriteLine($"现在是{time}，您设定的闹钟响了！");
        }
         DateTime alarmTime = new DateTime();
        public DateTime AlarmTime
        {
            get { return alarmTime; }
            set
            {
                alarmTime = value;
                Console.WriteLine($"设定时间为{alarmTime}");

            }
        }
        public void Start()
        {
            while (true)
            {
                DateTime now = DateTime.Now;
                OnTick(this, now);
                if (now.ToString() == alarmTime.ToString())
                {
                    OnAlarm(this, alarmTime);
                }
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
     
}
